<template>
  <p-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">

        <p-form-item label="物料编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'code', validatorRules.code]" placeholder="请输入物料编号"></p-input>
        </p-form-item>
        <p-form-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'name', validatorRules.name]" placeholder="请输入物料名称"></p-input>
        </p-form-item>
        <p-form-item label="物料有效期（单位：天/月）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'materialValidity', validatorRules.materialValidity]" placeholder="请输入物料有效期（单位：天/月）"></p-input>
        </p-form-item>
        <p-form-item label="最小单元体" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'minimumElement', validatorRules.minimumElement]" placeholder="请输入最小单元体"></p-input>
        </p-form-item>
        <p-form-item label="执行标准" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'executiveStandard', validatorRules.executiveStandard]" placeholder="请输入执行标准"></p-input>
        </p-form-item>
        <p-form-item label="是否为SN" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['whetherSn', validatorRules.whetherSn]" :trigger-change="true" dictCode="mat_whether_sn" placeholder="请选择是否为SN"/>
        </p-form-item>
        <p-form-item label="温度范围" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'temperatureRange', validatorRules.temperatureRange]" placeholder="请输入温度范围"></p-input>
        </p-form-item>
        <p-form-item label="湿度范围" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'humidityRange', validatorRules.humidityRange]" placeholder="请输入湿度范围"></p-input>
        </p-form-item>
        <p-form-item label="长" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'length', validatorRules.length]" placeholder="请输入长"></p-input>
        </p-form-item>
        <p-form-item label="宽" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'wide', validatorRules.wide]" placeholder="请输入宽"></p-input>
        </p-form-item>
        <p-form-item label="高" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'high', validatorRules.high]" placeholder="请输入高"></p-input>
        </p-form-item>
        <p-form-item label="二次超期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择二次超期" v-decorator="[ 'overDue', validatorRules.overDue]" :trigger-change="true" style="width: 100%"/>
        </p-form-item>
        <p-form-item label="是否进出口" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'whetherExport', validatorRules.whetherExport]" placeholder="请输入是否进出口"></p-input>
        </p-form-item>
        <p-form-item label="颜色" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'colour', validatorRules.colour]" placeholder="请输入颜色"></p-input>
        </p-form-item>
        <p-form-item label="每盒数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input-number v-decorator="[ 'cartonNumber', validatorRules.cartonNumber]" placeholder="请输入每盒数量" style="width: 100%"/>
        </p-form-item>
        <p-form-item label="每箱数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input-number v-decorator="[ 'boxNumber', validatorRules.boxNumber]" placeholder="请输入每箱数量" style="width: 100%"/>
        </p-form-item>
        <p-form-item label="单件标准净重" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input-number v-decorator="[ 'suttleWeight', validatorRules.suttleWeight]" placeholder="请输入单件标准净重" style="width: 100%"/>
        </p-form-item>
        <p-form-item label="单件标准毛重" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input-number v-decorator="[ 'grossWeight', validatorRules.grossWeight]" placeholder="请输入单件标准毛重" style="width: 100%"/>
        </p-form-item>
        <p-form-item label="外箱尺寸" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'cartonSize', validatorRules.cartonSize]" placeholder="请输入外箱尺寸"></p-input>
        </p-form-item>
        <p-form-item label="更新人标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'updatetimeBy', validatorRules.updatetimeBy]" placeholder="请输入更新人标识"></p-input>
        </p-form-item>
        <p-form-item label="更新时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择更新时间" v-decorator="[ 'updatetimeTime', validatorRules.updatetimeTime]" :trigger-change="true" style="width: 100%"/>
        </p-form-item>
        <p-form-item label="时间标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择时间标识" v-decorator="[ 'timestamp', validatorRules.timestamp]" :trigger-change="true" style="width: 100%"/>
        </p-form-item>
        <p-form-item label="公司标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'companyId', validatorRules.companyId]" placeholder="请输入公司标识"></p-input>
        </p-form-item>
        <p-form-item label="工厂标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'factoryId', validatorRules.factoryId]" placeholder="请输入工厂标识"></p-input>
        </p-form-item>
        <p-form-item label="租户标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'clientId', validatorRules.clientId]" placeholder="请输入租户标识"></p-input>
        </p-form-item>
        <p-form-item label="替换人员标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'substituteId', validatorRules.substituteId]" placeholder="请输入替换人员标识"></p-input>
        </p-form-item>
        <p-form-item label="物料类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'className', validatorRules.className]" placeholder="请输入物料类别"></p-input>
        </p-form-item>
        <p-form-item label="公司" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'company', validatorRules.company]" placeholder="请输入公司"></p-input>
        </p-form-item>
        <p-form-item label="工厂" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'factory', validatorRules.factory]" placeholder="请输入工厂"></p-input>
        </p-form-item>
        <p-form-item label="物料状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['status', validatorRules.status]" :trigger-change="true" dictCode="mat_status" placeholder="请选择物料状态"/>
        </p-form-item>
        <p-form-item label="物料规格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <p-input v-decorator="[ 'size', validatorRules.size]" placeholder="请输入物料规格"></p-input>
        </p-form-item>
        <p-form-item label="生效时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择生效时间" v-decorator="[ 'effectiveTime', validatorRules.effectiveTime]" :trigger-change="true" style="width: 100%"/>
        </p-form-item>

      </p-form>
    </p-spin>
    <p-button type="primary" @click="handleOk">确定</p-button>
    <p-button type="primary" @click="handleCancel">取消</p-button>
  </p-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  
  export default {
    name: "MaterialWmsModal",
    components: { 
      JDate,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          code: {rules: [
          ]},
          name: {rules: [
            {required: true, message: '请输入物料名称!'},
          ]},
          materialValidity: {rules: [
          ]},
          minimumElement: {rules: [
          ]},
          executiveStandard: {rules: [
          ]},
          whetherSn: {rules: [
          ]},
          temperatureRange: {rules: [
          ]},
          humidityRange: {rules: [
          ]},
          length: {rules: [
          ]},
          wide: {rules: [
          ]},
          high: {rules: [
          ]},
          overDue: {rules: [
          ]},
          whetherExport: {rules: [
          ]},
          colour: {rules: [
          ]},
          cartonNumber: {rules: [
          ]},
          boxNumber: {rules: [
          ]},
          suttleWeight: {rules: [
          ]},
          grossWeight: {rules: [
          ]},
          cartonSize: {rules: [
          ]},
          updatetimeBy: {rules: [
          ]},
          updatetimeTime: {rules: [
          ]},
          timestamp: {rules: [
          ]},
          companyId: {rules: [
          ]},
          factoryId: {rules: [
          ]},
          clientId: {rules: [
          ]},
          substituteId: {rules: [
          ]},
          className: {rules: [
          ]},
          company: {rules: [
          ]},
          factory: {rules: [
          ]},
          status: {rules: [
          ]},
          size: {rules: [
          ]},
          effectiveTime: {rules: [
          ]},
        },
        url: {
          add: '/basic-business/basicWms/materialWms/add',
          edit: '/basic-business/basicWms/materialWms/edit',
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },

      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'code','name','materialValidity','minimumElement','executiveStandard','whetherSn','temperatureRange','humidityRange','length','wide','high','overDue','whetherExport','colour','cartonNumber','boxNumber','suttleWeight','grossWeight','cartonSize','updatetimeBy','updatetimeTime','timestamp','companyId','factoryId','clientId','substituteId','className','company','factory','status','size','effectiveTime'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.msg);
                that.$emit('ok');
              }else{
                that.$message.warning(res.msg);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'code','name','materialValidity','minimumElement','executiveStandard','whetherSn','temperatureRange','humidityRange','length','wide','high','overDue','whetherExport','colour','cartonNumber','boxNumber','suttleWeight','grossWeight','cartonSize','updatetimeBy','updatetimeTime','timestamp','companyId','factoryId','clientId','substituteId','className','company','factory','status','size','effectiveTime'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>